package com.atwy.common.exception;

import com.atwy.common.RespBean;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常不生效问题，springboot默认扫面启动类当前所在包下，要保证异常处理类也在其扫描之下才能起作用
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RespBean runtimeExceptionHandle(RuntimeException e) {
        return RespBean.error(e.getMessage());
    }
}
